package com.chooongg.adapter.viewHolder

import android.util.SparseArray
import android.view.View
import androidx.annotation.IdRes
import androidx.annotation.Keep
import androidx.recyclerview.widget.RecyclerView

@Keep
open class BoxViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    private val views: SparseArray<View> = SparseArray()

    @Suppress("UNCHECKED_CAST")
    open fun <T : View> find(@IdRes viewId: Int): T? {
        val view = views.get(viewId)
        if (view == null) {
            itemView.findViewById<T>(viewId)?.let {
                views.put(viewId, it)
                return it
            }
        }
        return view as? T
    }
}